package threads;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class MyStack {

	private List<String> list = Collections.synchronizedList(new ArrayList<String>());
	//也可以使用CopyOnWriteArrayList
//	private List<String> list = new CopyOnWriteArrayList<String>();

	public synchronized void push(String value) {
		list.add(value);
		notify();
	}

	public synchronized String pop() throws InterruptedException {
		while (list.size() <= 0) {
			wait();
		}
		return list.remove(list.size() - 1);
	}

}
